/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef COMMSERVER_H
#define COMMSERVER_H

#include <string>

#include "EventServer.h"

namespace Chronos {

class Session;
class CommChannel;

class CommServer : public EventListener {
public:
	CommServer(EventServer& eventServer_);
	~CommServer();
	void notify(Event::EventType event, Session& session);

	void addChannel(const std::string& name, const char* color);

	void write(Session& session, const std::string& channelName, const std::string& msg);
    void listChannels(Session& session) const;
    void join(Session& session, const std::string& channelName);
    void leave(Session& session, const std::string& channelName);
    void showChannelMembers(Session& session, const std::string& channelName) const;
    void addPlayerChannel(Session& session, const std::string& channelName, const char* color);
private:
	CommChannel* findChannel(const std::string& name) const;
    void addPlayerToAllChannels(Session& session);
    void removePlayerFromAllChannels(Session& session);
    void checkForRemoval(Session& session, const std::string& channelName);

	EventServer& eventServer;

	typedef std::map<std::string, CommChannel*> Channels;
	typedef Channels::const_iterator ChannelsConstIter;
	typedef Channels::iterator ChannelsIter;
	Channels channels;
};

}

#endif

